package com.boco.ibssystem.business.service.config.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.boco.biinjectionserviceapi.dto.SummaryDto;
import com.boco.biinjectionserviceapi.model.config.ModelConfigEntity;
import com.boco.biinjectionserviceapi.service.config.ICommonModelConfigService;
import com.boco.ibssystem.business.mapper.config.DimPreConfigMapper;
import com.boco.ibssystem.business.mapper.config.ModelConfigMapper;
import com.boco.ibssystem.common.base.AbstractService;
import com.boco.sp.external.service.IDicCommonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @Description: 用于图块的基础数据的查询和组装实现
 * @Author: yc
 * @CreateDate: 2019/5/15$ 15:38$
 * @UpdateUser: yc
 * @UpdateDate: 2019/5/15$ 15:38$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */

@Service
public class CommonModelConfigServiceImpl extends AbstractService implements ICommonModelConfigService {

    @Resource
    private ModelConfigMapper modelConfigMapper;

    @Resource
    private DimPreConfigMapper dimPreConfigMapper;

    /**
     * 根据图块ID获取图块需要的信息
     *
     * @param modelId
     * @return SummaryDto
     */

    @Override
    public SummaryDto getSummaryModelById(int modelId) {
        String result = decryptCode("22222","333333");
        SummaryDto summaryDto = modelConfigMapper.selectById(modelId);
        //设置性能指标
        Integer[] dimIndexArray = Convert.toIntArray(summaryDto.getDimIndexs()) ;
        summaryDto.setDimConfigList(dimPreConfigMapper.selectBatchIds(Arrays.asList(dimIndexArray)));
        //设置离散维度
        summaryDto.setPreConfig(dimPreConfigMapper.selectById(summaryDto.getPreIndex()));
        return summaryDto;
    }


    @Override
    public SummaryDto getSummaryModelByParams(ModelConfigEntity modelConfig) {
        QueryWrapper queryWrapper = new QueryWrapper(modelConfig);
        SummaryDto summaryDto = modelConfigMapper.selectOne(queryWrapper);
        //设置性能指标
        Integer[] dimIndexArray = Convert.toIntArray(summaryDto.getDimIndexs()) ;
        summaryDto.setDimConfigList(dimPreConfigMapper.selectBatchIds(Arrays.asList(dimIndexArray)));
        //设置离散维度
        summaryDto.setPreConfig(dimPreConfigMapper.selectById(summaryDto.getPreIndex()));
        return summaryDto;
    }


}
